package com.yanqu.road.dao.impl.activity.jianchuanghua;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.jianchuanghua.ChuangHuaComb;
import com.yanqu.road.utils.property.PropertyHelper;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class ChuangHuaCombDaoImpl extends TempDao {

    private static final String getChuangHuaCombSql = "select * from t_s_activity_chuanghua_comb where activityId = ? order by combId asc";

    public List<ChuangHuaComb> getChuangHuaCombList(int activityId) {
        List<ChuangHuaComb> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getChuangHuaCombSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ChuangHuaComb chuangHuaComb = new ChuangHuaComb();
                chuangHuaComb.setActivityId(rs.getInt("activityId"));
                chuangHuaComb.setCombId(rs.getInt("combId"));
                chuangHuaComb.setName(rs.getString("name"));
                chuangHuaComb.setDesc(rs.getString("desc"));
                chuangHuaComb.setQuality(rs.getInt("quality"));
                chuangHuaComb.setElement(rs.getString("element"));
                chuangHuaComb.setSort(rs.getInt("sort"));
                chuangHuaComb.setElementProp(PropertyHelper.parseStringToProperty(chuangHuaComb.getElement(), "\\|"));
                list.add(chuangHuaComb);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
